﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using DotSpatial.Topology;

namespace HAGISV2
{
    [Serializable]
   public class PolyShape:VectorShape
    {

       
        public PolyShape(string id,string polyKey ,Coordinate[] coords,List<List<Coordinate>> polyHoles):base(id)
        {
            this._polyKey = polyKey;

            if (polyHoles != null && polyHoles.Count > 0)
            {
                List<LinearRing> lrs=new List<LinearRing>();
                LinearRing lr;
                foreach (List<Coordinate> item in polyHoles)
                {
                    if (item.Count >= 3)
                    {
                        lr = new LinearRing(item);
                        lrs.Add(lr);
                    }
                }

                if (lrs.Count > 0)
                {
                    for (int i = 0; i < lrs.Count; i++)
                    {
                        _holes.Add(lrs[i].Coordinates.ToList());
                        _holes[i].RemoveAt(_holes[i].Count - 1);
                    }
                    this._geometry = new Polygon(new LinearRing(coords), lrs.ToArray());
                }
                else
                    this._geometry = new Polygon(coords);
            }
            else
                this._geometry = new Polygon(coords);
        }


        public PolyShape(string id,string polyKey ,IGeometry geo)
            : base(id)
        {
            this._polyKey = polyKey;
            this._geometry = geo;
        }



        string _polyKey;
        /// <summary>
        /// 与多边形线对应
        /// </summary>
        public string PolyKey
        {
            get { return _polyKey; }
            set { _polyKey = value; }
        }


        List<List<Coordinate>> _holes = new List<List<Coordinate>>();

        public List<List<Coordinate>> Holes
        {
            get { return _holes; }
            set { _holes = value; }
        }

    }
}
